#include "UTHValue.h"

namespace phnq
{
	namespace uth
	{
		UTHValue::UTHValue(unsigned int type)
		{
			this->type = type;
			this->retainCount = 1;
		}

		UTHValue::~UTHValue()
		{
		}

		void UTHValue::retain()
		{
			if(type != UTH_VALUE_TYPE_UNDEFINED && type != UTH_VALUE_TYPE_NULL)
				retainCount++;
		}
	
		void UTHValue::release()
		{
			if(type != UTH_VALUE_TYPE_UNDEFINED && type != UTH_VALUE_TYPE_NULL)
			{
				retainCount--;
		
				if(retainCount == 0)
					delete this;
			}
		}
	
		bool UTHValue::isObject()
		{
			return this->type == UTH_VALUE_TYPE_OBJECT;
		}

		bool UTHValue::isFunction()
		{
			return this->type == UTH_VALUE_TYPE_FUNCTION;
		}

		bool UTHValue::isArray()
		{
			return this->type == UTH_VALUE_TYPE_ARRAY;
		}

		bool UTHValue::isString()
		{
			return this->type == UTH_VALUE_TYPE_STRING;
		}

		bool UTHValue::isNumber()
		{
			return this->type == UTH_VALUE_TYPE_NUMBER;
		}
	
		bool UTHValue::isUndefined()
		{
			return this->type == UTH_VALUE_TYPE_UNDEFINED;
		}
	
		bool UTHValue::isNull()
		{
			return this->type == UTH_VALUE_TYPE_NULL;
		}
	
		string UTHValue::toString()
		{
			stringbuf sb;
			serialize(&sb);
			return sb.str();
		}
	
		bool UTHValue::equals(UTHValue *val)
		{
			return this == val;
		}
	
		int UTHValue::hash()
		{
			return (int)this;
		}
	}
}
